package org.example.sdpback.sdk.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;

/**
 * @ProjectName: sdp-back
 * @Package: org.example.sdpback.sdk.response
 * @ClassName: SdpResponseData
 * @Author: zhuxingyue
 * @Description: 响应结果类
 * @Date: 2024/10/31 17:28
 * @Version: 1.0
 **/

@Data
public class SdpResponseData<T> implements Serializable {
    @Schema(name = "code", description = "响应码")
    private Integer code;
    @Schema(name = "message", description = "响应消息")
    private String message;
    @Schema(name = "data", description = "响应数据")
    private T data;

    /**
     * 无参构造函数
     */
    private SdpResponseData() {
        this.code = ResponseCode.Success.getCode();
        this.message = ResponseCode.Success.getMessage();
    }
    /**
     * 有参构造函数-自定义消息
     */
    private SdpResponseData(String message){
        this.code = ResponseCode.Success.getCode();
        this.message = message;
    }

    /**
     * 自定义返回数据
     * @param data
     */
    private SdpResponseData(T data) {
        this.code = ResponseCode.Success.getCode();
        this.message = ResponseCode.Success.getMessage();
        this.data = data;
    }

    /**
     * 自定义返回状态码，消息
     * @param responseCode
     */
    private SdpResponseData(ResponseCode responseCode){
        this.code = responseCode.getCode();
        this.message = responseCode.getMessage();
    }

    /**
     * 自定义返回消息，数据
     * @param message
     * @param data
     */
    private SdpResponseData(String message, T data) {
        this.code = ResponseCode.Success.getCode();
        this.message = message;
        this.data = data;
    }

    /**
     * 自定义返回状态码，数据
     * @param responseCode
     * @param data
     */
    private SdpResponseData(ResponseCode responseCode, T data) {
        this.code = responseCode.getCode();
        this.message = responseCode.getMessage();
        this.data = data;
    }

    /**
     * 自定义返回状态码，消息
     * @param responseCode
     * @param message
     */
    private SdpResponseData(ResponseCode responseCode, String message) {
        this.code = responseCode.getCode();
        this.message = message;
    }

    /**
     * 返回成功
     * @return
     * @param <T>
     */
    public static <T> SdpResponseData<T> success(){
        return new SdpResponseData<>();
    }

    /**
     * 返回成功，自定义数据
     * @return
     * @param <T>
     */
    public static <T> SdpResponseData<T> success(T data){
        return new SdpResponseData<>(data);
    }

    /**
     * 返回成功，自定义消息
     * @param message
     * @return
     * @param <T>
     */
    public static <T> SdpResponseData<T> success(String message){
        return new SdpResponseData<>(message);
    }

    /**
     * 返回成功，自定义状态码和数据
     * @param responseCode
     * @param data
     * @return
     * @param <T>
     */
    public static <T> SdpResponseData<T> success(ResponseCode responseCode, T data){
        return new SdpResponseData<>(responseCode, data);
    }

    /**
     * 返回失败
     * @return
     * @param <T>
     */
    public static <T> SdpResponseData<T> fail(){
        return new SdpResponseData<>(ResponseCode.Fail);
    }

    public static <T> SdpResponseData<T> fail(String message){
        return new SdpResponseData<>(ResponseCode.Fail, message);
    }

    public static <T> SdpResponseData<T> fail(ResponseCode responseCode){
        return new SdpResponseData<>(responseCode);
    }
}
